﻿
    window.onload = function () {
        var action = getQueryString("action");

        var Path_Data;
        if (document.getElementById("Path_Data")) {
            Path_Data = document.getElementById("Path_Data");
        }
        var Path_DataIcon = document.getElementById("Path_DataIcon");
        var SaveButton = document.getElementById("SaveButton");
        var deletedata = document.getElementById("deletedata");
        var editdata = document.getElementById("editdata");
        var DownLoadData;
        if (document.getElementById("DownLoadData")) {
            DownLoadData = document.getElementById("DownLoadData");
        }
        var DownLoadData_none = document.getElementById("DownLoadData_none");
        var ViewDataIcon_none = document.getElementById("ViewDataIcon_none");
        var ViewDataIcon = document.getElementById("ViewDataIcon");
        //var ViewDataIcon_upload = document.getElementById("ViewDataIcon_upload");
        //ViewDataIcon_upload.style.display = "none";
        var DownLoadData_upload;
        if (document.getElementById("DownLoadData_upload")) {
            DownLoadData_upload = document.getElementById("DownLoadData_upload");
            DownLoadData_upload.style.display = "none";
        }
        if (action == "create") {
        //    Path_Data.style.display = "";
        //    Path_DataIcon.style.display = "";
        //    SaveButton.style.display = "";
        //    deletedata.style.display = "none";
        //    editdata.style.display = "none";
        //    DownLoadData.style.display = "none";
        //    DownLoadData_none.style.display = "none";
        //    ViewDataIcon_none.style.display = "none";
        //    ViewDataIcon.style.display = "none";
        }
        else if (action == "edit") {

            ReadOnlyInput(true);

            //访问后台读取信息

            //获取的资源地址
            var path_Data = "/file/图件/规划数据/专题规划成果/城市建设类/中心城区用地规划图.jpg";
            //var path_Data = "";
            //获取的资源图标地址
            var path_DataIcon = "/img/onemap/catalog/data/中心城区用地图.jpg";
            //var path_DataIcon = "";

            if (DownLoadData) {
                if (path_Data != null && path_Data != "") {
                    DownLoadData.style.display = "";
                    DownLoadData_none.style.display = "none";
                    //DownLoadData.href = path_Data;
                }
                else {
                    DownLoadData_none.style.display = "";
                    DownLoadData.style.display = "none";
                }
            }
            
            if (path_DataIcon != null && path_DataIcon != "") {

                ViewDataIcon_none.style.display = "none";
                ViewDataIcon.style.display = "";
                //ViewDataIcon.href = path_DataIcon;
            }
            else {
                ViewDataIcon_none.style.display = "";
                ViewDataIcon.style.display = "none";
            }
            if (Path_Data) {
                Path_Data.style.display = "none";
            }
            Path_DataIcon.style.display = "none";
            SaveButton.style.display = "";
            deletedata.style.display = "";
            editdata.style.display = "";
        }

    }

function getQueryString(name) {
    const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    const urlObj = window.location;
    var r = urlObj.href.indexOf('#') > -1 ? urlObj.hash.split("?")[1].match(reg) : urlObj.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}


function EditInfo() {
    var SaveButton = document.getElementById("SaveButton");
    SaveButton.style.display = "";

    var ViewDataIcon_none = document.getElementById("ViewDataIcon_none");
    var ViewDataIcon_upload = document.getElementById("ViewDataIcon_upload");
    var Path_DataIcon = document.getElementById("Path_DataIcon");
    ViewDataIcon_upload.style.display = "";

    var DownLoadData_none = document.getElementById("DownLoadData_none");
    var DownLoadData_upload = document.getElementById("DownLoadData_upload");
    var Path_Data = document.getElementById("Path_Data");
    DownLoadData_upload.style.display = "";


    if (ViewDataIcon_none.style.display == "none" && Path_DataIcon.style.display == "none") {
        ViewDataIcon_upload.innerText = "重新上传";
        ViewDataIcon_upload.style.display = "";
    }
    else if (ViewDataIcon_none.style.display == "" && Path_DataIcon.style.display == "none") {
        ViewDataIcon_upload.style.display = "";
        ViewDataIcon_upload.innerText = "请上传";
    }
    else {
        ViewDataIcon_upload.style.display = "none";
    }


    if (DownLoadData_none.style.display == "none" && Path_Data.style.display == "none") {
        DownLoadData_upload.innerText = "重新上传";
        DownLoadData_upload.style.display = "";
    }
    else if (DownLoadData_none.style.display == "" && Path_Data.style.display == "none") {
        DownLoadData_upload.style.display = "";
        DownLoadData_upload.innerText = "请上传";
    }
    else {
        DownLoadData_upload.style.display = "none";
    }

    ReadOnlyInput(false);
}

function UploadFile(name) {
    if (name == "DataIcon") {
        var ViewDataIcon_none = document.getElementById("ViewDataIcon_none");
        var ViewDataIcon_upload = document.getElementById("ViewDataIcon_upload");
        var ViewDataIcon = document.getElementById("ViewDataIcon");
        var Path_DataIcon = document.getElementById("Path_DataIcon");
        ViewDataIcon_none.style.display = "none";
        ViewDataIcon_upload.style.display = "none";
        Path_DataIcon.style.display = "";
        ViewDataIcon.style.display = "none";
    }
    else if (name == "DownLoadData") {
        var DownLoadData_none = document.getElementById("DownLoadData_none");
        var DownLoadData_upload = document.getElementById("DownLoadData_upload");
        var DownLoadData = document.getElementById("DownLoadData");
        var Path_Data = document.getElementById("Path_Data");
        DownLoadData_none.style.display = "none";
        DownLoadData_upload.style.display = "none";
        Path_Data.style.display = "";
        DownLoadData.style.display = "none";
    }
}


function ReadOnlyInput(isReadOnly) {
    var allInputs = document.getElementsByTagName('input');
    for (var i = 0; i < allInputs.length; i++) {
        if (allInputs[i].type == 'text') {
            allInputs[i].readOnly = isReadOnly;
        }
    }

    var alltextareas = document.getElementsByTagName('textarea');
    for (var i = 0; i < alltextareas.length; i++) {
        alltextareas[i].readOnly = isReadOnly;
    }
}